// /*
//  * @Author: WanYiMing
//  * @Date:2024-03-04-15:40
//  * @Description:
//  */

using UnityEngine;

namespace Code.Utility
{
    public class RectTransformRotatorUtils
    {
        private float targetAngle;
        private float startAngle;
        private float rotateStartTime;
        private float rotateDuration;


        public  void SetRectTransformRotator(float targetRotation, float duration,RectTransform rectTransform)
        {
            this.targetAngle = targetRotation;
            this.startAngle = rectTransform.eulerAngles.z;
            this.rotateStartTime = Time.time;
            this.rotateDuration = duration;
        }


        public Vector3 Rotate()
        {
            float t = (Time.time - rotateStartTime) / rotateDuration;
            float currentAngle = Mathf.LerpAngle(startAngle, targetAngle, t);
            return new Vector3(0, 0, currentAngle);
        }

        public bool RotateEnd()
        {
            if (Time.time - rotateStartTime > rotateDuration)
            {
                return true;
            }
            return false;
        }
    }
}